home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / RGASM.RAR / ASMCODE.EXE / CHAPT8 / PG0802.ASM < prev    next >
Encoding:
Assembly Source File  |  1993-05-10  |  6.9 KB  |  146 lines

  1. ;***********************************************************************
  2. ;
  3. ;  Program PG0802 ( Chapter 8 )
  4. ;
  5. ;  Drawing colored net in graphics mode
  6. ;
  7. ;  Author: A.I.Sopin, VSU, Voronezh, 1992
  8. ;
  9. ;  BIOS video service is used (functiuon 0Ch of interrupt 10h)
  10. ;
  11. ;***********************************************************************
  12. .model  small
  13. EXTRN   VIDTYP : FAR
  14. .stack
  15. .data
  16. ;----------------------------------------------------------
  17. N       DW      0       ;  horizontal knots (0, 1 - 64)
  18. M       DW      0       ;  vertical knots (0, 1 - 40)
  19. X       DW      0       ;  horizontal coordinate of pixel (0 - 639)
  20. Y       DW      0       ;  vertical coordinate of pixel (0 - 339)
  21. H_Leng  DW      640     ;  number of points in horisontal direction
  22. V_Leng  DW      400     ;  number of points in vertical direction
  23. Nstr    DW      0       ;  number of lines for output (1 --- 340)
  24. V_Count DW      0       ;  vertical pixel counter (1 --- 18)
  25. Col     DB      0       ;  color (0 --- 15)
  26. VMODE   DB      0       ;  original video mode
  27. TEXT0   DB      ' Demo program for working in graphics mode  (BIOS  INT 10h).'
  28.     DB      13,10
  29.     DB      ' Press any key for change color or ESC to exit.', 7, '$'
  30. TEXT1   DB      13, 10
  31.     DB      ' EGA or VGA  card not installed !  Press any key...', '$'
  32. ;----------------------------------------------------------
  33. .code
  34. .startup
  35.     mov     ah,0Fh                  ;  function 0Fh - get video mode
  36.     int     10h                     ;  BIOS video service call
  37.     mov     VMODE,al                ;  save original video mode
  38.     mov     ah,00                   ;  function 00h - set video mode
  39.     mov     al,03h                  ;  mode 3 (80x25  color)
  40.     int     10h                     ;  BIOS video service call
  41.     mov     ah,2                    ;  function 02h - set cursor
  42.     mov     dx,0                    ;  initial cursor position - 0, 0
  43.     mov     bh,0                    ;  video page 0
  44.     int     10h                     ;  BIOS video service call
  45. ;  Check whether EGA or VGA installed
  46.     Call    VIDTYP                  ;  determine cideo adapter type
  47.     cmp     al,3                    ;  EGA  or  VGA ?
  48.     jnl     Graph                   ;  OK
  49.     lea     dx,TEXT1                ;  address of string for output
  50.     mov     ah,9                    ;  function 09h - output string
  51.     int     21h                     ;  DOS service call
  52.     mov     ah,0                    ;  function 00h - get key
  53.     int     16h                     ;  BIOS keyboard service call
  54.     jmp     short Exit              ;  to finishing program
  55. ;  Output initial message and set graphics mode
  56. Graph:  lea     dx,TEXT0                ;  address of string for output
  57.     mov     ah,9                    ;  function 09h - output string
  58.     int     21h                     ;  DOS service call
  59.     xor     ah,ah                   ;  function 00h - get key
  60.     int     16h                     ;  BIOS keyboard service call
  61.     mov     ah,0                    ;  function 00h - set video mode
  62.     mov     al,10h                  ;  Color  640x350
  63.     int     10h                     ;  BIOS video service call
  64.     mov     Col,0                   ;  set initial color (black)
  65. ;-------------------------------------------------------------------
  66. ;  Output colored net into the screen
  67. Loop0:  mov     Nstr,0                  ;  upper line number
  68. Loop1:  Call    HORLINE                 ;  draw horizontal line
  69.     Call    VLINES                  ;  output vertical lines
  70.     add     Nstr,20                 ;  Next Line
  71.     cmp     Nstr,340                ;  Last Line ?
  72.     jl      Loop1                   ;
  73. ;  Change color when a key has been pressed
  74.     xor     ah,ah                   ;  function 00h - get key
  75.     int     16h                     ;  BIOS keyboard service call
  76.     cmp     al,1Bh                  ;  Esc ?
  77.     je      Exit                    ;  yes, finish program
  78.     inc     Col                     ;  change color code
  79.     cmp     Col,15                  ;  all colors shown?
  80.     jng     Loop0                   ;  no, show next color
  81.     mov     Col,0                   ;  set initial color (black)
  82.     jmp     short Loop0             ;  continue
  83. ;-------------------------------------------------------------------
  84. ;  Finish program and return to MS-DOS
  85. Exit:   mov     ah,0                    ;  function 0 - set video mode
  86.     mov     al,VMODE                ;  AL - original mode
  87.     int     10h                     ;  BIOS video service call
  88.     mov     ax,4C00h                ;  Function 4Ch - terminate process
  89.     int     21h                     ;  DOS service call
  90. ;-------------------------------------------------------------------
  91. ;
  92. ;  Output horizontal line
  93. ;
  94. ;-------------------------------------------------------------------
  95. HORLINE PROC   NEAR
  96.     xor     cx,cx                   ;  X - initial column for output
  97. HOR1:   mov     ah,0Ch                  ;  function 0Ch - output pixel
  98.     mov     al,Col                  ;  pixel color (bright red)
  99.     mov     dx,Nstr                 ;  Y - row for output
  100.     mov     bh,0                    ;  video page 0
  101.     int     10h                     ;  BIOS video service call
  102.     inc     cx                      ;  to next pixel
  103.     cmp     cx,H_Leng               ;  end of line?
  104.     jl      HOR1                    ;  not - continue output
  105.     RETN                            ;  return to caller
  106. HORLINE ENDP
  107. ;-------------------------------------------------------------------
  108. ;
  109. ;  Drawing vertical lines from knots
  110. ;
  111. ;  Is performed after a horizontal line has been output
  112. ;
  113. ;  CX - horizontal pixel coordinate (row)
  114. ;
  115. ;  DX - vertical pixel coordinate (column)
  116. ;
  117. ;-------------------------------------------------------------------
  118. VLINES  PROC   NEAR
  119.     cmp     Nstr,340                ;  Last Line ?
  120.     je      VLIN5                   ;  yes, return
  121.     cmp     Nstr,0                  ;  first line ?
  122.     jz      VLIN5                   ;  yes, return
  123.     xor     cx,cx                   ;  initial column = 0
  124. VLIN2:  mov     V_Count,20              ;  length of vertical line
  125.     mov     dx,Nstr                 ;  initial row
  126.     sub     dx,19                   ;  number of pixel
  127. ;  Output vertical line from upper line to current line
  128. VLIN3:  mov     ah,0Ch                  ;  function 0Ch - output pixel
  129.     mov     al,Col                  ;  pixel color
  130.     mov     bh,0                    ;  video page 0
  131.     int     10h                     ;  BIOS video service call
  132.     inc     dx                      ;  addres of low pixel
  133.     dec     V_Count                 ;
  134.     jg      VLIN3                   ;  continue output
  135. ;  Next knot in horizontal direction
  136.     mov     si,32                   ;  length of string
  137.     and     cx,cx                   ;  begiining of the line?
  138.     jg      VLIN4                   ;  no
  139.     mov     si,31                   ;  to knot 2
  140. VLIN4:  add     cx,si                   ;  next horizontal knot
  141.     cmp     cx,639                  ;  end of line?
  142.     jng     VLIN2                   ;
  143. VLIN5:  RETN                            ;  return
  144. VLINES  ENDP
  145.     END
  146.